package com.antler.smt.portal.controller;

import com.antler.smt.entity.DictionaryEntity;
import com.antler.smt.model.SiteMap;
import com.antler.smt.portal.mapper.DictionaryInfoMapper;
import com.antler.smt.response.base.Result;
import com.antler.smt.utils.JacksonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * TODO
 *
 * @author vic
 * @date 2018-04-11 19:25
 *  
 */
@RestController
@RequestMapping(value = "/siteMap")
@Api(description = "网站地图接口")
public class SiteMapController {

    @Autowired
    DictionaryInfoMapper dictionaryInfoMapper;
    /**
     * 搜索
     *
     * @param text
     * @return
     */
    @GetMapping("/search/{text}")
    @ApiOperation(value = "搜索", httpMethod = "GET")
    public Result listArea(@PathVariable String text) {

        DictionaryEntity entity = dictionaryInfoMapper.selectByKey("siteMap");
        List<SiteMap> maps = Arrays.asList(JacksonUtil.readValue(entity.getdValue(), SiteMap[].class));
        SiteMap result = null;
        for (SiteMap map : maps) {
            if (map.getText().contains(text)) {
                result = map;
                break;
            }
        }
        return new Result(result);
    }
}
